package com.thti.mecool.client.activity;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.thti.mecool.client.base.BaseActivity;
import com.thti.mecool.client.util.StringUtil;
import com.thti.mecool.client.util.Util;
import com.thti.mecool.client.widget.AlterDialogWidget;
import com.thti.mecool.client.widget.Toolbar;

public class SaleUploadActivity extends BaseActivity{
	private LinearLayout selectProjectLinearLayout,selectStoreLinearLayout;
	private Button sureButton;
	private TextView projectContent,storeContent;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		noTitle();
		setContentView(R.layout.mecool_sale_upload);
		initToolbar();
		init();
		service();
	}

	public void initToolbar() {
		Toolbar toolbar = new Toolbar(this);
		toolbar.setToolbarCentreText("销量上报");
		Toolbar.left_btn.setOnClickListener(leftbuttonListener);
		Toolbar.left_btn.setImageResource(R.drawable.mecool_go_back);
		Toolbar.hideRightButton();
	}
	
	private OnClickListener leftbuttonListener = new ImageButton.OnClickListener() {
		@Override
		public void onClick(View v) {
			finish();
		}
	};
	
	private void init(){
		selectProjectLinearLayout=(LinearLayout)findViewById(R.id.mecool_sale_upload_select_project);
		selectStoreLinearLayout=(LinearLayout)findViewById(R.id.mecool_sale_upload_select_shop);
		sureButton=(Button)findViewById(R.id.mecool_sale_upload_sure);
		projectContent=(TextView)findViewById(R.id.mecool_sale_upload_select_project_content);
		storeContent=(TextView)findViewById(R.id.mecool_sale_upload_select_shop_content);
	}
	
	private void service(){
		selectProjectLinearLayout.setOnClickListener(clickListener);
		selectStoreLinearLayout.setOnClickListener(clickListener);
		sureButton.setOnClickListener(clickListener);
		
	}
	
	
	OnClickListener clickListener=new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch(v.getId()){
			case R.id.mecool_sale_upload_select_project:
				AlterDialogWidget shopDialog=new AlterDialogWidget(SaleUploadActivity.this);
				shopDialog.setTitle("选择所在项目");
				shopDialog.setItems(new String[]{"项目一","项目二","项目三","项目四"});
				shopDialog.setReturnView(projectContent);
				storeContent.setText("");
				shopDialog.show();
				break;
			case R.id.mecool_sale_upload_select_shop:
				if(StringUtil.isBlank(projectContent.getText().toString())){
					Util.sendToast(SaleUploadActivity.this, "请您先选择项目");
				}else{
					AlterDialogWidget shopDialog1=new AlterDialogWidget(SaleUploadActivity.this);
					shopDialog1.setTitle("选择所在项目");
					shopDialog1.setItems(new String[]{"门店一","门店二","门店三","门店四"});
					shopDialog1.setReturnView(storeContent);
					shopDialog1.show();
				}
				break;
			case R.id.mecool_sale_upload_sure: 
				if(judge()){
					Util.sendToast(SaleUploadActivity.this, "提交数据成功");
					Intent intent=new Intent(SaleUploadActivity.this,SaleSKUActivity.class);
					ArrayList<String> itemNameList=new ArrayList<String>();
					itemNameList.add("三聚氰胺");
					itemNameList.add("猛牛");
					itemNameList.add("地沟油");
					intent.putExtra("ItemNameList", itemNameList);
					intent.putExtra("titlename",projectContent.getText().toString()+"-"+storeContent.getText().toString());
					intent.putExtra("isadd", true);
					startActivity(intent);
					finish();
				}else{
					Util.sendToast(SaleUploadActivity.this, "所填项不能为空!");
				}
				break;
			}
		}
	};
	
	
	private boolean judge(){
		if(StringUtil.isBlank(projectContent.getText().toString())){
			return false;
		}
		if(StringUtil.isBlank(storeContent.getText().toString())){
			return false;
		}
		return true;
	}

}
